<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>bubble.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_editor_bubble.js.html">bubble.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2005 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Bubble component - handles display, hiding, etc. of the
<a name="line17"></a> * actual bubble UI.
<a name="line18"></a> *
<a name="line19"></a> * This is used exclusively by code within the editor package, and should not
<a name="line20"></a> * be used directly.
<a name="line21"></a> *
<a name="line22"></a> * @author robbyw@google.com (Robby Walker)
<a name="line23"></a> * @author tildahl@google.com (Michael Tildahl)
<a name="line24"></a> */
<a name="line25"></a>
<a name="line26"></a>goog.provide(&#39;goog.ui.editor.Bubble&#39;);
<a name="line27"></a>
<a name="line28"></a>goog.require(&#39;goog.debug.Logger&#39;);
<a name="line29"></a>goog.require(&#39;goog.dom&#39;);
<a name="line30"></a>goog.require(&#39;goog.dom.ViewportSizeMonitor&#39;);
<a name="line31"></a>goog.require(&#39;goog.editor.style&#39;);
<a name="line32"></a>goog.require(&#39;goog.events&#39;);
<a name="line33"></a>goog.require(&#39;goog.events.EventHandler&#39;);
<a name="line34"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line35"></a>goog.require(&#39;goog.math.Box&#39;);
<a name="line36"></a>goog.require(&#39;goog.positioning&#39;);
<a name="line37"></a>goog.require(&#39;goog.string&#39;);
<a name="line38"></a>goog.require(&#39;goog.style&#39;);
<a name="line39"></a>goog.require(&#39;goog.ui.Component.EventType&#39;);
<a name="line40"></a>goog.require(&#39;goog.ui.PopupBase&#39;);
<a name="line41"></a>goog.require(&#39;goog.ui.PopupBase.EventType&#39;);
<a name="line42"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line43"></a>
<a name="line44"></a>
<a name="line45"></a>
<a name="line46"></a>/**
<a name="line47"></a> * Property bubble UI element.
<a name="line48"></a> * @param {Element} parent The parent element for this bubble.
<a name="line49"></a> * @param {number} zIndex The z index to draw the bubble at.
<a name="line50"></a> * @constructor
<a name="line51"></a> * @extends {goog.events.EventTarget}
<a name="line52"></a> */
<a name="line53"></a>goog.ui.editor.Bubble = function(parent, zIndex) {
<a name="line54"></a>  goog.base(this);
<a name="line55"></a>
<a name="line56"></a>  /**
<a name="line57"></a>   * Dom helper for the document the bubble should be shown in.
<a name="line58"></a>   * @type {!goog.dom.DomHelper}
<a name="line59"></a>   * @private
<a name="line60"></a>   */
<a name="line61"></a>  this.dom_ = goog.dom.getDomHelper(parent);
<a name="line62"></a>
<a name="line63"></a>  /**
<a name="line64"></a>   * Event handler for this bubble.
<a name="line65"></a>   * @type {goog.events.EventHandler}
<a name="line66"></a>   * @private
<a name="line67"></a>   */
<a name="line68"></a>  this.eventHandler_ = new goog.events.EventHandler(this);
<a name="line69"></a>
<a name="line70"></a>  /**
<a name="line71"></a>   * Object that monitors the application window for size changes.
<a name="line72"></a>   * @type {goog.dom.ViewportSizeMonitor}
<a name="line73"></a>   * @private
<a name="line74"></a>   */
<a name="line75"></a>  this.viewPortSizeMonitor_ = new goog.dom.ViewportSizeMonitor(
<a name="line76"></a>      this.dom_.getWindow());
<a name="line77"></a>
<a name="line78"></a>  /**
<a name="line79"></a>   * Maps panel ids to panels.
<a name="line80"></a>   * @type {Object.&lt;goog.ui.editor.Bubble.Panel_&gt;}
<a name="line81"></a>   * @private
<a name="line82"></a>   */
<a name="line83"></a>  this.panels_ = {};
<a name="line84"></a>
<a name="line85"></a>  /**
<a name="line86"></a>   * Container element for the entire bubble.  This may contain elements related
<a name="line87"></a>   * to look and feel or styling of the bubble.
<a name="line88"></a>   * @type {Element}
<a name="line89"></a>   * @private
<a name="line90"></a>   */
<a name="line91"></a>  this.bubbleContainer_ =
<a name="line92"></a>      this.dom_.createDom(goog.dom.TagName.DIV,
<a name="line93"></a>          {&#39;className&#39;: goog.ui.editor.Bubble.BUBBLE_CLASSNAME});
<a name="line94"></a>
<a name="line95"></a>  goog.style.showElement(this.bubbleContainer_, false);
<a name="line96"></a>  goog.dom.appendChild(parent, this.bubbleContainer_);
<a name="line97"></a>  goog.style.setStyle(this.bubbleContainer_, &#39;zIndex&#39;, zIndex);
<a name="line98"></a>
<a name="line99"></a>  /**
<a name="line100"></a>   * Container element for the bubble panels - this should be some inner element
<a name="line101"></a>   * within (or equal to) bubbleContainer.
<a name="line102"></a>   * @type {Element}
<a name="line103"></a>   * @private
<a name="line104"></a>   */
<a name="line105"></a>  this.bubbleContents_ = this.createBubbleDom(this.dom_, this.bubbleContainer_);
<a name="line106"></a>
<a name="line107"></a>  /**
<a name="line108"></a>   * Element showing the close box.
<a name="line109"></a>   * @type {!Element}
<a name="line110"></a>   * @private
<a name="line111"></a>   */
<a name="line112"></a>  this.closeBox_ = this.dom_.createDom(goog.dom.TagName.DIV, {
<a name="line113"></a>    &#39;className&#39;: goog.getCssName(&#39;tr_bubble_closebox&#39;),
<a name="line114"></a>    &#39;innerHTML&#39;: &#39;&amp;nbsp;&#39;
<a name="line115"></a>  });
<a name="line116"></a>  this.bubbleContents_.appendChild(this.closeBox_);
<a name="line117"></a>
<a name="line118"></a>  // We make bubbles unselectable so that clicking on them does not steal focus
<a name="line119"></a>  // or move the cursor away from the element the bubble is attached to.
<a name="line120"></a>  goog.editor.style.makeUnselectable(this.bubbleContainer_, this.eventHandler_);
<a name="line121"></a>
<a name="line122"></a>  /**
<a name="line123"></a>   * Popup that controls showing and hiding the bubble at the appropriate
<a name="line124"></a>   * position.
<a name="line125"></a>   * @type {goog.ui.PopupBase}
<a name="line126"></a>   * @private
<a name="line127"></a>   */
<a name="line128"></a>  this.popup_ = new goog.ui.PopupBase(this.bubbleContainer_);
<a name="line129"></a>};
<a name="line130"></a>goog.inherits(goog.ui.editor.Bubble, goog.events.EventTarget);
<a name="line131"></a>
<a name="line132"></a>
<a name="line133"></a>/**
<a name="line134"></a> * The css class name of the bubble container element.
<a name="line135"></a> * @type {string}
<a name="line136"></a> */
<a name="line137"></a>goog.ui.editor.Bubble.BUBBLE_CLASSNAME = goog.getCssName(&#39;tr_bubble&#39;);
<a name="line138"></a>
<a name="line139"></a>
<a name="line140"></a>/**
<a name="line141"></a> * Creates and adds DOM for the bubble UI to the given container.  This default
<a name="line142"></a> * implementation just returns the container itself.
<a name="line143"></a> * @param {!goog.dom.DomHelper} dom DOM helper to use.
<a name="line144"></a> * @param {!Element} container Element to add the new elements to.
<a name="line145"></a> * @return {!Element} The element where bubble content should be added.
<a name="line146"></a> * @protected
<a name="line147"></a> */
<a name="line148"></a>goog.ui.editor.Bubble.prototype.createBubbleDom = function(dom, container) {
<a name="line149"></a>  return container;
<a name="line150"></a>};
<a name="line151"></a>
<a name="line152"></a>
<a name="line153"></a>/**
<a name="line154"></a> * A logger for goog.ui.editor.Bubble.
<a name="line155"></a> * @type {goog.debug.Logger}
<a name="line156"></a> * @protected
<a name="line157"></a> */
<a name="line158"></a>goog.ui.editor.Bubble.prototype.logger =
<a name="line159"></a>    goog.debug.Logger.getLogger(&#39;goog.ui.editor.Bubble&#39;);
<a name="line160"></a>
<a name="line161"></a>
<a name="line162"></a>/** @override */
<a name="line163"></a>goog.ui.editor.Bubble.prototype.disposeInternal = function() {
<a name="line164"></a>  goog.base(this, &#39;disposeInternal&#39;);
<a name="line165"></a>
<a name="line166"></a>  goog.dom.removeNode(this.bubbleContainer_);
<a name="line167"></a>  this.bubbleContainer_ = null;
<a name="line168"></a>
<a name="line169"></a>  this.eventHandler_.dispose();
<a name="line170"></a>  this.eventHandler_ = null;
<a name="line171"></a>
<a name="line172"></a>  this.viewPortSizeMonitor_.dispose();
<a name="line173"></a>  this.viewPortSizeMonitor_ = null;
<a name="line174"></a>};
<a name="line175"></a>
<a name="line176"></a>
<a name="line177"></a>/**
<a name="line178"></a> * @return {Element} The element that where the bubble&#39;s contents go.
<a name="line179"></a> */
<a name="line180"></a>goog.ui.editor.Bubble.prototype.getContentElement = function() {
<a name="line181"></a>  return this.bubbleContents_;
<a name="line182"></a>};
<a name="line183"></a>
<a name="line184"></a>
<a name="line185"></a>/**
<a name="line186"></a> * @return {Element} The element that contains the bubble.
<a name="line187"></a> * @protected
<a name="line188"></a> */
<a name="line189"></a>goog.ui.editor.Bubble.prototype.getContainerElement = function() {
<a name="line190"></a>  return this.bubbleContainer_;
<a name="line191"></a>};
<a name="line192"></a>
<a name="line193"></a>
<a name="line194"></a>/**
<a name="line195"></a> * @return {goog.events.EventHandler} The event handler.
<a name="line196"></a> * @protected
<a name="line197"></a> */
<a name="line198"></a>goog.ui.editor.Bubble.prototype.getEventHandler = function() {
<a name="line199"></a>  return this.eventHandler_;
<a name="line200"></a>};
<a name="line201"></a>
<a name="line202"></a>
<a name="line203"></a>/**
<a name="line204"></a> * Handles user resizing of window.
<a name="line205"></a> * @private
<a name="line206"></a> */
<a name="line207"></a>goog.ui.editor.Bubble.prototype.handleWindowResize_ = function() {
<a name="line208"></a>  if (this.isVisible()) {
<a name="line209"></a>    this.reposition();
<a name="line210"></a>  }
<a name="line211"></a>};
<a name="line212"></a>
<a name="line213"></a>
<a name="line214"></a>/**
<a name="line215"></a> * Returns whether there is already a panel of the given type.
<a name="line216"></a> * @param {string} type Type of panel to check.
<a name="line217"></a> * @return {boolean} Whether there is already a panel of the given type.
<a name="line218"></a> */
<a name="line219"></a>goog.ui.editor.Bubble.prototype.hasPanelOfType = function(type) {
<a name="line220"></a>  return goog.object.some(this.panels_, function(panel) {
<a name="line221"></a>    return panel.type == type;
<a name="line222"></a>  });
<a name="line223"></a>};
<a name="line224"></a>
<a name="line225"></a>
<a name="line226"></a>/**
<a name="line227"></a> * Adds a panel to the bubble.
<a name="line228"></a> * @param {string} type The type of bubble panel this is.  Should usually be
<a name="line229"></a> *     the same as the tagName of the targetElement.  This ensures multiple
<a name="line230"></a> *     bubble panels don&#39;t appear for the same element.
<a name="line231"></a> * @param {string} title The title of the panel.
<a name="line232"></a> * @param {Element} targetElement The target element of the bubble.
<a name="line233"></a> * @param {function(Element): void} contentFn Function that when called with
<a name="line234"></a> *     a container element, will add relevant panel content to it.
<a name="line235"></a> * @param {boolean=} opt_preferTopPosition Whether to prefer placing the bubble
<a name="line236"></a> *     above the element instead of below it.  Defaults to preferring below.
<a name="line237"></a> *     If any panel prefers the top position, the top position is used.
<a name="line238"></a> * @return {string} The id of the panel.
<a name="line239"></a> */
<a name="line240"></a>goog.ui.editor.Bubble.prototype.addPanel = function(type, title, targetElement,
<a name="line241"></a>    contentFn, opt_preferTopPosition) {
<a name="line242"></a>  var id = goog.string.createUniqueString();
<a name="line243"></a>  var panel = new goog.ui.editor.Bubble.Panel_(this.dom_, id, type, title,
<a name="line244"></a>      targetElement, !opt_preferTopPosition);
<a name="line245"></a>  this.panels_[id] = panel;
<a name="line246"></a>
<a name="line247"></a>  // Insert the panel in string order of type.  Technically we could use binary
<a name="line248"></a>  // search here but n is really small (probably 0 - 2) so it&#39;s not worth it.
<a name="line249"></a>  // The last child of bubbleContents_ is the close box so we take care not
<a name="line250"></a>  // to treat it as a panel element, and we also ensure it stays as the last
<a name="line251"></a>  // element.  The intention here is not to create any artificial order, but
<a name="line252"></a>  // just to ensure that it is always consistent.
<a name="line253"></a>  var nextElement;
<a name="line254"></a>  for (var i = 0, len = this.bubbleContents_.childNodes.length - 1; i &lt; len;
<a name="line255"></a>       i++) {
<a name="line256"></a>    var otherChild = this.bubbleContents_.childNodes[i];
<a name="line257"></a>    var otherPanel = this.panels_[otherChild.id];
<a name="line258"></a>    if (otherPanel.type &gt; type) {
<a name="line259"></a>      nextElement = otherChild;
<a name="line260"></a>      break;
<a name="line261"></a>    }
<a name="line262"></a>  }
<a name="line263"></a>  goog.dom.insertSiblingBefore(panel.element,
<a name="line264"></a>      nextElement || this.bubbleContents_.lastChild);
<a name="line265"></a>
<a name="line266"></a>  contentFn(panel.getContentElement());
<a name="line267"></a>  goog.editor.style.makeUnselectable(panel.element, this.eventHandler_);
<a name="line268"></a>
<a name="line269"></a>  var numPanels = goog.object.getCount(this.panels_);
<a name="line270"></a>  if (numPanels == 1) {
<a name="line271"></a>    this.openBubble_();
<a name="line272"></a>  } else if (numPanels == 2) {
<a name="line273"></a>    goog.dom.classes.add(this.bubbleContainer_,
<a name="line274"></a>        goog.getCssName(&#39;tr_multi_bubble&#39;));
<a name="line275"></a>  }
<a name="line276"></a>  this.reposition();
<a name="line277"></a>
<a name="line278"></a>  return id;
<a name="line279"></a>};
<a name="line280"></a>
<a name="line281"></a>
<a name="line282"></a>/**
<a name="line283"></a> * Removes the panel with the given id.
<a name="line284"></a> * @param {string} id The id of the panel.
<a name="line285"></a> */
<a name="line286"></a>goog.ui.editor.Bubble.prototype.removePanel = function(id) {
<a name="line287"></a>  var panel = this.panels_[id];
<a name="line288"></a>  goog.dom.removeNode(panel.element);
<a name="line289"></a>  delete this.panels_[id];
<a name="line290"></a>
<a name="line291"></a>  var numPanels = goog.object.getCount(this.panels_);
<a name="line292"></a>  if (numPanels &lt;= 1) {
<a name="line293"></a>    goog.dom.classes.remove(this.bubbleContainer_,
<a name="line294"></a>        goog.getCssName(&#39;tr_multi_bubble&#39;));
<a name="line295"></a>  }
<a name="line296"></a>
<a name="line297"></a>  if (numPanels == 0) {
<a name="line298"></a>    this.closeBubble_();
<a name="line299"></a>  } else {
<a name="line300"></a>    this.reposition();
<a name="line301"></a>  }
<a name="line302"></a>};
<a name="line303"></a>
<a name="line304"></a>
<a name="line305"></a>/**
<a name="line306"></a> * Opens the bubble.
<a name="line307"></a> * @private
<a name="line308"></a> */
<a name="line309"></a>goog.ui.editor.Bubble.prototype.openBubble_ = function() {
<a name="line310"></a>  this.eventHandler_.
<a name="line311"></a>      listen(this.closeBox_, goog.events.EventType.CLICK,
<a name="line312"></a>          this.closeBubble_).
<a name="line313"></a>      listen(this.viewPortSizeMonitor_,
<a name="line314"></a>          goog.events.EventType.RESIZE, this.handleWindowResize_).
<a name="line315"></a>      listen(this.popup_, goog.ui.PopupBase.EventType.HIDE,
<a name="line316"></a>          this.handlePopupHide);
<a name="line317"></a>
<a name="line318"></a>  this.popup_.setVisible(true);
<a name="line319"></a>  this.reposition();
<a name="line320"></a>};
<a name="line321"></a>
<a name="line322"></a>
<a name="line323"></a>/**
<a name="line324"></a> * Closes the bubble.
<a name="line325"></a> * @private
<a name="line326"></a> */
<a name="line327"></a>goog.ui.editor.Bubble.prototype.closeBubble_ = function() {
<a name="line328"></a>  this.popup_.setVisible(false);
<a name="line329"></a>};
<a name="line330"></a>
<a name="line331"></a>
<a name="line332"></a>/**
<a name="line333"></a> * Handles the popup&#39;s hide event by removing all panels and dispatching a
<a name="line334"></a> * HIDE event.
<a name="line335"></a> * @protected
<a name="line336"></a> */
<a name="line337"></a>goog.ui.editor.Bubble.prototype.handlePopupHide = function() {
<a name="line338"></a>  // Remove the panel elements.
<a name="line339"></a>  for (var panelId in this.panels_) {
<a name="line340"></a>    goog.dom.removeNode(this.panels_[panelId].element);
<a name="line341"></a>  }
<a name="line342"></a>
<a name="line343"></a>  // Update the state to reflect no panels.
<a name="line344"></a>  this.panels_ = {};
<a name="line345"></a>  goog.dom.classes.remove(this.bubbleContainer_,
<a name="line346"></a>      goog.getCssName(&#39;tr_multi_bubble&#39;));
<a name="line347"></a>
<a name="line348"></a>  this.eventHandler_.removeAll();
<a name="line349"></a>  this.dispatchEvent(goog.ui.Component.EventType.HIDE);
<a name="line350"></a>};
<a name="line351"></a>
<a name="line352"></a>
<a name="line353"></a>/**
<a name="line354"></a> * Returns the visibility of the bubble.
<a name="line355"></a> * @return {boolean} True if visible false if not.
<a name="line356"></a> */
<a name="line357"></a>goog.ui.editor.Bubble.prototype.isVisible = function() {
<a name="line358"></a>  return this.popup_.isVisible();
<a name="line359"></a>};
<a name="line360"></a>
<a name="line361"></a>
<a name="line362"></a>/**
<a name="line363"></a> * The vertical clearance in pixels between the bottom of the targetElement
<a name="line364"></a> * and the edge of the bubble.
<a name="line365"></a> * @type {number}
<a name="line366"></a> * @private
<a name="line367"></a> */
<a name="line368"></a>goog.ui.editor.Bubble.VERTICAL_CLEARANCE_ = goog.userAgent.IE ? 4 : 2;
<a name="line369"></a>
<a name="line370"></a>
<a name="line371"></a>/**
<a name="line372"></a> * Bubble&#39;s margin box to be passed to goog.positioning.
<a name="line373"></a> * @type {goog.math.Box}
<a name="line374"></a> * @private
<a name="line375"></a> */
<a name="line376"></a>goog.ui.editor.Bubble.MARGIN_BOX_ = new goog.math.Box(
<a name="line377"></a>    goog.ui.editor.Bubble.VERTICAL_CLEARANCE_, 0,
<a name="line378"></a>    goog.ui.editor.Bubble.VERTICAL_CLEARANCE_, 0);
<a name="line379"></a>
<a name="line380"></a>
<a name="line381"></a>/**
<a name="line382"></a> * Positions and displays this bubble below its targetElement. Assumes that
<a name="line383"></a> * the bubbleContainer is already contained in the document object it applies
<a name="line384"></a> * to.
<a name="line385"></a> */
<a name="line386"></a>goog.ui.editor.Bubble.prototype.reposition = function() {
<a name="line387"></a>  var targetElement = null;
<a name="line388"></a>  var preferBottomPosition = true;
<a name="line389"></a>  for (var panelId in this.panels_) {
<a name="line390"></a>    var panel = this.panels_[panelId];
<a name="line391"></a>    // We don&#39;t care which targetElement we get, so we just take the last one.
<a name="line392"></a>    targetElement = panel.targetElement;
<a name="line393"></a>    preferBottomPosition = preferBottomPosition &amp;&amp; panel.preferBottomPosition;
<a name="line394"></a>  }
<a name="line395"></a>  var status = goog.positioning.OverflowStatus.FAILED;
<a name="line396"></a>
<a name="line397"></a>  // Fix for bug when bubbleContainer and targetElement have
<a name="line398"></a>  // opposite directionality, the bubble should anchor to the END of
<a name="line399"></a>  // the targetElement instead of START.
<a name="line400"></a>  var reverseLayout = (goog.style.isRightToLeft(this.bubbleContainer_) !=
<a name="line401"></a>      goog.style.isRightToLeft(targetElement));
<a name="line402"></a>
<a name="line403"></a>  // Try to put the bubble at the bottom of the target unless the plugin has
<a name="line404"></a>  // requested otherwise.
<a name="line405"></a>  if (preferBottomPosition) {
<a name="line406"></a>    status = this.positionAtAnchor_(reverseLayout ?
<a name="line407"></a>        goog.positioning.Corner.BOTTOM_END :
<a name="line408"></a>        goog.positioning.Corner.BOTTOM_START,
<a name="line409"></a>        goog.positioning.Corner.TOP_START,
<a name="line410"></a>        goog.positioning.Overflow.ADJUST_X | goog.positioning.Overflow.FAIL_Y);
<a name="line411"></a>  }
<a name="line412"></a>
<a name="line413"></a>  if (status &amp; goog.positioning.OverflowStatus.FAILED) {
<a name="line414"></a>    // Try to put it at the top of the target if there is not enough
<a name="line415"></a>    // space at the bottom.
<a name="line416"></a>    status = this.positionAtAnchor_(reverseLayout ?
<a name="line417"></a>        goog.positioning.Corner.TOP_END : goog.positioning.Corner.TOP_START,
<a name="line418"></a>        goog.positioning.Corner.BOTTOM_START,
<a name="line419"></a>        goog.positioning.Overflow.ADJUST_X | goog.positioning.Overflow.FAIL_Y);
<a name="line420"></a>  }
<a name="line421"></a>
<a name="line422"></a>  if (status &amp; goog.positioning.OverflowStatus.FAILED) {
<a name="line423"></a>    // Put it at the bottom again with adjustment if there is no
<a name="line424"></a>    // enough space at the top.
<a name="line425"></a>    status = this.positionAtAnchor_(reverseLayout ?
<a name="line426"></a>        goog.positioning.Corner.BOTTOM_END :
<a name="line427"></a>        goog.positioning.Corner.BOTTOM_START,
<a name="line428"></a>        goog.positioning.Corner.TOP_START,
<a name="line429"></a>        goog.positioning.Overflow.ADJUST_X |
<a name="line430"></a>        goog.positioning.Overflow.ADJUST_Y);
<a name="line431"></a>    if (status &amp; goog.positioning.OverflowStatus.FAILED) {
<a name="line432"></a>      this.logger.warning(
<a name="line433"></a>          &#39;reposition(): positionAtAnchor() failed with &#39; + status);
<a name="line434"></a>    }
<a name="line435"></a>  }
<a name="line436"></a>};
<a name="line437"></a>
<a name="line438"></a>
<a name="line439"></a>/**
<a name="line440"></a> * A helper for reposition() - positions the bubble in regards to the position
<a name="line441"></a> * of the elements the bubble is attached to.
<a name="line442"></a> * @param {goog.positioning.Corner} targetCorner The corner of
<a name="line443"></a> *     the target element.
<a name="line444"></a> * @param {goog.positioning.Corner} bubbleCorner The corner of the bubble.
<a name="line445"></a> * @param {number} overflow Overflow handling mode bitmap,
<a name="line446"></a> *     {@see goog.positioning.Overflow}.
<a name="line447"></a> * @return {number} Status bitmap, {@see goog.positioning.OverflowStatus}.
<a name="line448"></a> * @private
<a name="line449"></a> */
<a name="line450"></a>goog.ui.editor.Bubble.prototype.positionAtAnchor_ = function(
<a name="line451"></a>    targetCorner, bubbleCorner, overflow) {
<a name="line452"></a>  var targetElement = null;
<a name="line453"></a>  for (var panelId in this.panels_) {
<a name="line454"></a>    // For now, we use the outermost element.  This assumes the multiple
<a name="line455"></a>    // elements this panel is showing for contain each other - in the event
<a name="line456"></a>    // that is not generally the case this may need to be updated to pick
<a name="line457"></a>    // the lowest or highest element depending on targetCorner.
<a name="line458"></a>    var candidate = this.panels_[panelId].targetElement;
<a name="line459"></a>    if (!targetElement || goog.dom.contains(candidate, targetElement)) {
<a name="line460"></a>      targetElement = this.panels_[panelId].targetElement;
<a name="line461"></a>    }
<a name="line462"></a>  }
<a name="line463"></a>  return goog.positioning.positionAtAnchor(
<a name="line464"></a>      targetElement, targetCorner, this.bubbleContainer_,
<a name="line465"></a>      bubbleCorner, null, goog.ui.editor.Bubble.MARGIN_BOX_, overflow);
<a name="line466"></a>};
<a name="line467"></a>
<a name="line468"></a>
<a name="line469"></a>
<a name="line470"></a>/**
<a name="line471"></a> * Private class used to describe a bubble panel.
<a name="line472"></a> * @param {goog.dom.DomHelper} dom DOM helper used to create the panel.
<a name="line473"></a> * @param {string} id ID of the panel.
<a name="line474"></a> * @param {string} type Type of the panel.
<a name="line475"></a> * @param {string} title Title of the panel.
<a name="line476"></a> * @param {Element} targetElement Element the panel is showing for.
<a name="line477"></a> * @param {boolean} preferBottomPosition Whether this panel prefers to show
<a name="line478"></a> *     below the target element.
<a name="line479"></a> * @constructor
<a name="line480"></a> * @private
<a name="line481"></a> */
<a name="line482"></a>goog.ui.editor.Bubble.Panel_ = function(dom, id, type, title, targetElement,
<a name="line483"></a>    preferBottomPosition) {
<a name="line484"></a>  /**
<a name="line485"></a>   * The type of bubble panel.
<a name="line486"></a>   * @type {string}
<a name="line487"></a>   */
<a name="line488"></a>  this.type = type;
<a name="line489"></a>
<a name="line490"></a>  /**
<a name="line491"></a>   * The target element of this bubble panel.
<a name="line492"></a>   * @type {Element}
<a name="line493"></a>   */
<a name="line494"></a>  this.targetElement = targetElement;
<a name="line495"></a>
<a name="line496"></a>  /**
<a name="line497"></a>   * Whether the panel prefers to be placed below the target element.
<a name="line498"></a>   * @type {boolean}
<a name="line499"></a>   */
<a name="line500"></a>  this.preferBottomPosition = preferBottomPosition;
<a name="line501"></a>
<a name="line502"></a>  /**
<a name="line503"></a>   * The element containing this panel.
<a name="line504"></a>   */
<a name="line505"></a>  this.element = dom.createDom(goog.dom.TagName.DIV,
<a name="line506"></a>      {className: goog.getCssName(&#39;tr_bubble_panel&#39;), id: id},
<a name="line507"></a>      dom.createDom(goog.dom.TagName.DIV,
<a name="line508"></a>          {className: goog.getCssName(&#39;tr_bubble_panel_title&#39;)},
<a name="line509"></a>          title + &#39;:&#39;), // TODO(robbyw): Does this work properly in bidi?
<a name="line510"></a>      dom.createDom(goog.dom.TagName.DIV,
<a name="line511"></a>          {className: goog.getCssName(&#39;tr_bubble_panel_content&#39;)}));
<a name="line512"></a>};
<a name="line513"></a>
<a name="line514"></a>
<a name="line515"></a>/**
<a name="line516"></a> * @return {Element} The element in the panel where content should go.
<a name="line517"></a> */
<a name="line518"></a>goog.ui.editor.Bubble.Panel_.prototype.getContentElement = function() {
<a name="line519"></a>  return /** @type {Element} */ (this.element.lastChild);
<a name="line520"></a>};
</pre>


</body>
</html>
